﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestDemo01
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Window_Loaded);
            
            this.Deactivated += new EventHandler(Window_Deactivated);
            this.Activated += new EventHandler(Window_Activated);
            this.Closing += new System.ComponentModel.CancelEventHandler(Window_Closing);

        }
        private bool isPlaying;

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 窗体加载时，显示当前日期及开始播放媒体
            myMedia.Source = new Uri(@"J:\凤凰demo\TesT\TestDemo01\TestDemo01\kk.wmv", UriKind.Absolute);
            txtDate.Text = DateTime.Now.ToString("yyy-MM-dd");
            myMedia.Play();
            isPlaying = true;

        }

        private void Window_Activated(object sender, EventArgs e)
        {
            // 如果窗体被激活，则继承播放媒体
            if (isPlaying)
            {
                myMedia.Pause();
                isPlaying = false;
            }
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //点击窗体的关闭 按钮，询问用户是否退出程序
            string message = "你确定要退出么？";
            string title = "提示信息";
            MessageBoxButton button = MessageBoxButton.OKCancel;
            MessageBoxImage img = MessageBoxImage.Question;
            MessageBoxResult result = MessageBox.Show(message,title,button,img);
            if (result == MessageBoxResult.Cancel)
            {
                e.Cancel = true; //取消退出
            }
        }

        private void Window_Deactivated(object sender, EventArgs e)
        {

        }
    }
}
